<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/10/4 0004
 * Time: 16:56
 */
namespace app\index\behavior;
use app\index\model\Admin;
use app\index\model\Role;
use think\Cookie;

class Authcheck{
    public function run(&$params){

        $username = explode('-',Cookie::get("auth"))[0];

        $urole_id = Admin::where("uname",$username)->value('urole');

        $rp_id = Role::where("r_id",$urole_id)->value('rp_id');

        $sel_arr = explode(',',$rp_id);

        $power_arr = \app\index\model\Controller::all($sel_arr);

        $tmp_qx = [];
        $i = 0;
        foreach ($power_arr as $k){
            $tmp_qx[$i] = $k->c_con;
            $i++;
        }

        $params_arr = array(explode('?',$params)[0]);

        //两个数组是否有交集来判断是否有权限
        if(sizeof(array_intersect($tmp_qx,$params_arr))!=0||$params=="/"){
            #echo "有权限操作";
        }else{
            //echo "deny";
            #dd($params_arr);
            #dd($tmp_qx);
            //exit(0);
        }


    }
}